package net.orange.framework.validator;

import net.orange.architecture.validator.IObjectValidator;
import net.orange.framework.model.Group;

/**
 * Validation : The group code should follow the special format: GXX, XX is two
 * digital number.
 */
public class GroupCodeFormatValidator extends FrameworkValidator implements
		IObjectValidator {
	/**
	 * The target group.
	 */
	private Group group;

	/**
	 * Disabled the default contractor.
	 */
	@SuppressWarnings("unused")
	private GroupCodeFormatValidator() throws Exception {

	}

	/**
	 * Constructor with group object to initialize the validation.
	 * 
	 * @param group
	 *            The target group.
	 */
	public GroupCodeFormatValidator(Group group) throws Exception {
		this.group = group;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.validator.ObjectValidator#check()
	 */
	public boolean check() throws Exception {
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.validator.ObjectValidator#getMessage()
	 */
	public String getMessage() {
		return "";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.validator.IObjectValidator#validate()
	 */
	public String validate() throws Exception {

		if (group.getGroup_code().length() != 3
				|| !group.getGroup_code().startsWith("G")) {
			return message.get("error2_grp_01");
		}
		String s = group.getGroup_code().substring(1, 3);

		try {
			Integer.parseInt(s);
		} catch (Exception e) {
			return message.get("error2_grp_02");
		}

		return null;
	}
}